<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二维码生成工具</title>
    <link rel="stylesheet" href="../coding/common.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/qrcode/1.5.1/qrcode.js"></script>
    <style>
        /* 基础样式和变量 */
        :root {
            --primary-color: #4a6fa5;
            --secondary-color: #6c8ebd;
            --background-color: #f5f7fa;
            --card-background: #ffffff;
            --text-color: #333333;
            --border-color: #e0e0e0;
            --error-color: #e74c3c;
            --success-color: #2ecc71;
            --shadow-color: rgba(0, 0, 0, 0.1);
            --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            --tip-background: #e3f2fd;
        }

        /* 暗黑模式变量 */
        [data-theme="dark"] {
            --primary-color: #5b8ad6;
            --secondary-color: #7fa3d7;
            --background-color: #1a1a2e;
            --card-background: #222438;
            --text-color: #e0e0e0;
            --border-color: #444444;
            --shadow-color: rgba(0, 0, 0, 0.3);
            --tip-background: #1a2a3a;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: var(--font-family);
            background-color: var(--background-color);
            color: var(--text-color);
            line-height: 1.6;
            transition: background-color 0.3s, color 0.3s;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 头部样式 */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
        }

        header h1 {
            font-size: 2rem;
            color: var(--primary-color);
        }

        /* 头部控件区域 */
        .header-controls {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        /* 分享按钮 */
        .share-button {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 2px 6px;
            background-color: var(--secondary-color);
            color: white;
            border-radius: 15px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .share-button:hover {
            background-color: var(--primary-color);
        }

        .share-button:active {
            transform: scale(0.98);
        }

        .share-button i {
            font-size: 16px;
        }

        /* 主题切换开关 */
        .theme-toggle {
            position: relative;
        }

        .theme-switch {
            opacity: 0;
            position: absolute;
        }

        .theme-switch-label {
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: pointer;
            width: 50px;
            height: 26px;
            background-color: #83d8ff;
            border-radius: 100px;
            position: relative;
            transition: background-color 0.3s;
            padding: 0 5px;
        }

        .theme-switch:checked + .theme-switch-label {
            background-color: #4a4e69;
        }

        .theme-switch-label .fa-sun {
            color: #f39c12;
        }

        .theme-switch-label .fa-moon {
            color: #f1c40f;
        }

        .theme-switch-label .slider {
            position: absolute;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            transition: 0.3s;
            background-color: white;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            left: 2px;
        }

        .theme-switch:checked + .theme-switch-label .slider {
            transform: translateX(24px);
        }

        /* 隐私提示框样式 */
        .privacy-notice {
            margin-bottom: 20px;
            animation: fadeIn 0.5s ease-in-out;
        }

        .privacy-notice-content {
            display: flex;
            align-items: center;
            background-color: var(--tip-background);
            border-left: 4px solid #2196f3;
            padding: 15px;
            border-radius: 4px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .privacy-notice-content i.fa-shield-alt {
            font-size: 20px;
            color: #2196f3;
            margin-right: 15px;
        }

        .privacy-notice-content p {
            flex: 1;
            margin: 0;
            font-size: 14px;
            color: var(--text-color);
        }

        .close-notice {
            background: none;
            border: none;
            color: #90a4ae;
            cursor: pointer;
            font-size: 16px;
            padding: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: color 0.2s;
        }

        .close-notice:hover {
            color: #546e7a;
            background: none;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 主内容区域 */
        main {
            flex: 1;
        }

        .qr-container {
            display: flex;
            gap: 30px;
            height: 600px;
        }

        .input-section {
            flex: 1;
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
            display: flex;
            flex-direction: column;
        }

        .input-section h2 {
            margin-bottom: 15px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .input-section h2 i {
            font-size: 1.2rem;
        }

        .input-group {
            display: flex;
            flex-direction: column;
            margin-bottom: 20px;
            flex: 1;
        }

        .input-group label {
            margin-bottom: 8px;
            font-weight: bold;
            color: var(--text-color);
        }

        .input-group textarea {
            flex: 1;
            padding: 12px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-family: var(--font-family);
            font-size: 14px;
            background-color: var(--card-background);
            color: var(--text-color);
            resize: vertical;
            min-height: 200px;
            transition: border-color 0.3s, background-color 0.3s, color 0.3s;
        }

        .input-group textarea:focus {
            outline: none;
            border-color: var(--primary-color);
        }

        .button-group {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
        }

        .button-group button {
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            background-color: var(--primary-color);
            color: white;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 8px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .button-group button:hover {
            background-color: var(--secondary-color);
        }

        .button-group button:active {
            transform: scale(0.98);
        }

        .button-group button i {
            font-size: 16px;
        }

        /* 批量生成按钮样式 */
        .batch-generate-btn {
            display: none;
        }

        /* 批量二维码弹框样式 */
        .batch-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }

        .batch-modal-content {
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 8px 32px var(--shadow-color);
            max-width: 90vw;
            max-height: 90vh;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            position: relative;
        }

        .batch-modal-header {
            padding: 20px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: var(--card-background);
        }

        .batch-modal-header h3 {
            margin: 0;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .batch-modal-close {
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: var(--text-color);
            padding: 5px;
            border-radius: 4px;
            transition: background-color 0.3s;
        }

        .batch-modal-close:hover {
            background-color: var(--border-color);
        }

        .batch-modal-body {
            padding: 20px;
            overflow-y: auto;
            flex: 1;
        }

        .batch-qr-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            max-height: 60vh;
            overflow-y: auto;
        }

        .batch-qr-item {
            background-color: var(--background-color);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 15px;
            text-align: center;
            transition: box-shadow 0.3s;
        }

        .batch-qr-item:hover {
            box-shadow: 0 4px 12px var(--shadow-color);
        }

        .batch-qr-item canvas {
            max-width: 100%;
            height: auto;
            border-radius: 4px;
            margin-bottom: 10px;
        }

        .batch-qr-text {
            font-size: 12px;
            color: var(--text-color);
            word-break: break-all;
            margin-bottom: 10px;
            max-height: 60px;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .batch-qr-actions {
            display: flex;
            gap: 5px;
            justify-content: center;
        }

        .batch-qr-actions button {
            padding: 5px 10px;
            border: none;
            border-radius: 4px;
            background-color: var(--secondary-color);
            color: white;
            cursor: pointer;
            font-size: 12px;
            transition: background-color 0.3s;
        }

        .batch-qr-actions button:hover {
            background-color: var(--primary-color);
        }

        .batch-modal-footer {
            padding: 15px 20px;
            border-top: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: var(--card-background);
        }

        .batch-count {
            color: var(--text-color);
            font-size: 14px;
        }

        .batch-download-all {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            background-color: var(--primary-color);
            color: white;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: background-color 0.3s;
        }

        .batch-download-all:hover {
            background-color: var(--secondary-color);
        }

        .qr-section {
            flex: 1;
            background-color: var(--card-background);
            border-radius: 8px;
            box-shadow: 0 4px 6px var(--shadow-color);
            padding: 20px;
            transition: background-color 0.3s, box-shadow 0.3s;
            display: flex;
            flex-direction: column;
        }

        .qr-section h2 {
            margin-bottom: 15px;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .qr-section h2 i {
            font-size: 1.2rem;
        }

        .qr-display {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px dashed var(--border-color);
            border-radius: 8px;
            background-color: var(--background-color);
            transition: border-color 0.3s, background-color 0.3s;
            position: relative;
        }

        .qr-display.has-qr {
            border-style: solid;
            border-color: var(--primary-color);
        }

        .qr-placeholder {
            text-align: center;
            color: var(--text-color);
            opacity: 0.6;
        }

        .qr-placeholder i {
            font-size: 48px;
            margin-bottom: 10px;
            display: block;
        }

        #qr-canvas {
            max-width: 100%;
            max-height: 100%;
            border-radius: 4px;
        }

        .qr-actions {
            margin-top: 15px;
            display: flex;
            gap: 10px;
            justify-content: center;
        }

        .qr-actions button {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            background-color: var(--secondary-color);
            color: white;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: background-color 0.3s, transform 0.1s;
        }

        .qr-actions button:hover {
            background-color: var(--primary-color);
        }

        .qr-actions button:active {
            transform: scale(0.98);
        }

        .qr-actions button:disabled {
            background-color: var(--border-color);
            cursor: not-allowed;
            opacity: 0.6;
        }

        .qr-actions button:disabled:hover {
            background-color: var(--border-color);
            transform: none;
        }

        /* 通知样式 */
        .notification {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: var(--success-color);
            color: white;
            padding: 12px 20px;
            border-radius: 4px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
            transform: translateY(100px);
            opacity: 0;
            transition: transform 0.3s, opacity 0.3s;
            z-index: 1000;
        }

        .notification.show {
            transform: translateY(0);
            opacity: 1;
        }

        .notification.error {
            background-color: var(--error-color);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .qr-container {
                flex-direction: column;
                height: auto;
                gap: 20px;
            }

            .input-section,
            .qr-section {
                min-height: 300px;
            }

            .button-group {
                flex-wrap: wrap;
            }

            .button-group button {
                flex: 1;
                min-width: 120px;
            }

            .qr-actions {
                flex-wrap: wrap;
            }

            .privacy-notice-content {
                flex-direction: column;
                text-align: center;
                padding: 15px 10px;
            }
            
            .privacy-notice-content i.fa-shield-alt {
                margin-right: 0;
                margin-bottom: 10px;
            }
            
            .close-notice {
                position: absolute;
                top: 5px;
                right: 5px;
            }

            header {
                flex-direction: column;
                gap: 15px;
                text-align: center;
            }
        }
    </style>
</head>
<body>
    <header>
        <div class="header-container">
            <div class="header-left">
                <div class="logo">
                    <span><a href="https://geekdaxue.co/" target="_blank"><img src="https://geekdaxue.co/static/images/logo_platypus.png" height="30px"></a></span>
                </div>
                <nav class="main-navigation">
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            JSON工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../json/index.html">JSON 格式化</a>
                            <a href="../json/parser.html">JSON 格式校验</a>
                            <a href="../json/excel.html">JSON 转 Excel/CSV</a>
                            <a href="../json/jsonxml.html">JSON 与 XML 转换</a>
                            <a href="../json/editor.html">JSON 编辑器</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            编码转换 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../coding/base64.html">Base64 编码</a>
                            <a href="../coding/urlencoding.html">URL 编码</a>
                            <a href="../coding/md5.html">MD5 加密</a>
                            <a href="../coding/unicode.html">Unicode 转换</a>
                            <a href="../coding/hex_convert.html">进制转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            文本工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../txt/diff.html">文本对比</a>
                            <a href="../txt/replace.html">文本替换</a>
                            <a href="../txt/remove.html">空白行移除</a>
                            <a href="../txt/cn_trans.html">繁简体转换</a>
                        </div>
                    </div>
                    <div class="nav-item dropdown">
                        <a href="#" class="nav-link">
                            图片工具 <i class="fas fa-chevron-down"></i>
                        </a>
                        <div class="dropdown-menu">
                            <a href="../img/2svg.html">图片转 SVG</a>
                            <a href="../img/qr_code.html">二维码生成</a>
                            <a href="../img/barcode.html">条形码生成</a>
                        </div>
                    </div>
                </nav>
            </div>
            <div class="header-controls">
                <div class="theme-toggle">
                    <input type="checkbox" id="theme-switch" class="theme-switch">
                    <label for="theme-switch" class="theme-switch-label">
                        <i class="fas fa-sun"></i>
                        <i class="fas fa-moon"></i>
                        <span class="slider"></span>
                    </label>
                </div>
                <div class="share-button" id="share-button" title="分享给朋友">
                    <i class="fas fa-share-alt"></i>
                    <span>分享</span>
                </div>
            </div>
        </div>
    </header>
    <div class="container">
        <div id="privacy-notice" class="privacy-notice">
            <div class="privacy-notice-content">
                <i class="fas fa-shield-alt"></i>
                <p>安全提示：您的数据仅在本地浏览器中处理，不会上传到服务器，请放心使用！</p>
                <button id="close-notice" class="close-notice" title="关闭提示">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        </div>
        
        <main>
            <div class="qr-container">
                <div class="input-section">
                    <h2><i class="fas fa-edit"></i> 输入内容</h2>
                    <div class="input-group">
                        <label for="qr-input">请输入要生成二维码的内容：</label>
                        <textarea id="qr-input" placeholder="请输入文本、网址、联系信息等内容...

示例：
• 网址：https://www.example.com
• 文本：Hello World
• 邮箱：example@email.com
• 电话：+86 138 0013 8000"></textarea>
                    </div>
                    <div class="button-group">
                        <button id="generate-btn">
                            <i class="fas fa-qrcode"></i> 生成二维码
                        </button>
                        <button id="batch-generate-btn" class="batch-generate-btn">
                            <i class="fas fa-layer-group"></i> 批量生成二维码
                        </button>
                        <button id="clear-btn">
                            <i class="fas fa-trash"></i> 清空
                        </button>
                    </div>
                </div>
                
                <div class="qr-section">
                    <h2><i class="fas fa-qrcode"></i> 二维码展示</h2>
                    <div class="qr-display" id="qr-display">
                        <div class="qr-placeholder" id="qr-placeholder">
                            <i class="fas fa-qrcode"></i>
                            <div>点击左侧"生成二维码"按钮<br>生成您的专属二维码</div>
                        </div>
                        <canvas id="qr-canvas" style="display: none;"></canvas>
                    </div>
                    <div class="qr-actions">
                        <button id="download-btn" disabled>
                            <i class="fas fa-download"></i> 下载
                        </button>
                        <button id="copy-btn" disabled>
                            <i class="fas fa-copy"></i> 复制图片
                        </button>
                    </div>
                </div>
            </div>
        </main>
    </div>
    <footer>
            <div class="footer-container">
                <div class="footer-main">
                    <div class="footer-section about-us">
                        <h3>关于我们</h3>
                        <p>我们提供一系列高效、便捷的在线工具，帮助开发者、非技术人员提高工作效率，解决日常开发中遇到的各种问题。</p>
                        <p>Build With <i class="fa-solid fa-heart" style="color: red;"></i> For SF.</p>
                    </div>
                    <div class="footer-section links">
                        <h3>工具导航</h3>
                        <div class="links-columns">
                            <ul>
                                <li><a href="../json/index.html">JSON 工具</a></li>
                                <li><a href="../img/index.html">图片处理</a></li>
                                <li><a href="#">开发工具</a></li>
                            </ul>
                            <ul>
                                <li><a href="../coding/index.html">编码转换</a></li>
                                <li><a href="../txt/index.html">文本工具</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="footer-section contact">
                        <h3>联系我们</h3>
                        <div class="social-icons">
                            <a href="#" title="GitHub"><i class="fab fa-github"></i></a>
                            <a href="#" title="Twitter"><i class="fab fa-twitter"></i></a>
                            <a href="#" title="WeChat"><i class="fab fa-weixin"></i></a>
                            <a href="mailto:example@example.com" title="Email"><i class="fas fa-envelope"></i></a>
                        </div>
                        <p>如有问题或建议，请随时联系我们</p>
                    </div>
                </div>
                <div class="footer-bottom">
                    <div class="footer-legal">
                        <a href="#">使用条款</a>
                        <a href="#">隐私政策</a>
                    </div>
                </div>
            </div>
        </footer>
    
    <div id="notification" class="notification"></div>
    
    <!-- 批量二维码弹框 -->
    <div id="batch-modal" class="batch-modal">
        <div class="batch-modal-content">
            <div class="batch-modal-header">
                <h3><i class="fas fa-layer-group"></i> 批量二维码</h3>
                <button id="batch-modal-close" class="batch-modal-close">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="batch-modal-body">
                <div id="batch-qr-grid" class="batch-qr-grid">
                    <!-- 批量二维码将在这里生成 -->
                </div>
            </div>
            <div class="batch-modal-footer">
                <div class="batch-count">
                    <span id="batch-count-text">共生成 0 个二维码</span>
                </div>
                <button id="batch-download-all" class="batch-download-all">
                    <i class="fas fa-download"></i> 下载全部
                </button>
            </div>
        </div>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const qrInput = document.getElementById('qr-input');
            const generateBtn = document.getElementById('generate-btn');
            const clearBtn = document.getElementById('clear-btn');
            const batchGenerateBtn = document.getElementById('batch-generate-btn');
            const qrDisplay = document.getElementById('qr-display');
            const qrPlaceholder = document.getElementById('qr-placeholder');
            const qrCanvas = document.getElementById('qr-canvas');
            const downloadBtn = document.getElementById('download-btn');
            const copyBtn = document.getElementById('copy-btn');
            const notification = document.getElementById('notification');
            const themeSwitch = document.getElementById('theme-switch');
            const privacyNotice = document.getElementById('privacy-notice');
            const closeNoticeBtn = document.getElementById('close-notice');
            const shareButton = document.getElementById('share-button');
            const batchModal = document.getElementById('batch-modal');
            const batchModalClose = document.getElementById('batch-modal-close');
            const batchQrGrid = document.getElementById('batch-qr-grid');
            const batchCountText = document.getElementById('batch-count-text');
            const batchDownloadAll = document.getElementById('batch-download-all');
            
            // 检查本地存储中的主题设置
            if (localStorage.getItem('theme') === 'dark') {
                document.body.setAttribute('data-theme', 'dark');
                themeSwitch.checked = true;
            }
            
            // 主题切换功能
            themeSwitch.addEventListener('change', function() {
                if (this.checked) {
                    document.body.setAttribute('data-theme', 'dark');
                    localStorage.setItem('theme', 'dark');
                } else {
                    document.body.removeAttribute('data-theme');
                    localStorage.setItem('theme', 'light');
                }
            });
            
            // 隐私提示框关闭功能
            closeNoticeBtn.addEventListener('click', function() {
                privacyNotice.style.display = 'none';
                localStorage.setItem('privacyNoticeClosed', 'true');
            });
            
            // 检查是否需要显示隐私提示
            if (localStorage.getItem('privacyNoticeClosed') === 'true') {
                privacyNotice.style.display = 'none';
            }
            
            // 分享功能
            shareButton.addEventListener('click', function() {
                copyToClipboard(window.location.href);
                showNotification('已复制网址，赶快让更多的小伙伴知道我吧！');
            });
            
            // 检测多行文本输入
            function checkMultilineInput() {
                const text = qrInput.value.trim();
                const lines = text.split('\n').filter(line => line.trim() !== '');
                
                if (lines.length > 1) {
                    batchGenerateBtn.style.display = 'flex';
                } else {
                    batchGenerateBtn.style.display = 'none';
                }
            }
            
            // 监听输入框变化
            qrInput.addEventListener('input', checkMultilineInput);
            qrInput.addEventListener('paste', function() {
                setTimeout(checkMultilineInput, 100);
            });
            
            // 生成二维码
            generateBtn.addEventListener('click', function() {
                const text = qrInput.value.trim();
                if (!text) {
                    showNotification('请输入要生成二维码的内容！', true);
                    return;
                }
                
                // 显示加载状态
                generateBtn.disabled = true;
                generateBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 生成中...';
                
                // 生成二维码
                QRCode.toCanvas(qrCanvas, text, {
                    width: 300,
                    height: 300,
                    margin: 2,
                    color: {
                        dark: getComputedStyle(document.documentElement).getPropertyValue('--text-color').trim(),
                        light: getComputedStyle(document.documentElement).getPropertyValue('--card-background').trim()
                    }
                }, function(error) {
                    // 恢复按钮状态
                    generateBtn.disabled = false;
                    generateBtn.innerHTML = '<i class="fas fa-qrcode"></i> 生成二维码';
                    
                    if (error) {
                        showNotification('生成二维码失败：' + error.message, true);
                        return;
                    }
                    
                    // 显示二维码
                    qrPlaceholder.style.display = 'none';
                    qrCanvas.style.display = 'block';
                    qrDisplay.classList.add('has-qr');
                    
                    // 启用操作按钮
                    downloadBtn.disabled = false;
                    copyBtn.disabled = false;
                    
                    showNotification('二维码生成成功！');
                });
            });
            
            // 清空内容
            clearBtn.addEventListener('click', function() {
                qrInput.value = '';
                qrPlaceholder.style.display = 'block';
                qrCanvas.style.display = 'none';
                qrDisplay.classList.remove('has-qr');
                downloadBtn.disabled = true;
                copyBtn.disabled = true;
                checkMultilineInput(); // 检查是否需要隐藏批量生成按钮
            });
            
            // 批量生成二维码
            batchGenerateBtn.addEventListener('click', function() {
                const text = qrInput.value.trim();
                const lines = text.split('\n').filter(line => line.trim() !== '');
                
                if (lines.length <= 1) {
                    showNotification('请输入多行内容进行批量生成！', true);
                    return;
                }
                
                // 清空之前的内容
                batchQrGrid.innerHTML = '';
                
                // 显示弹框
                batchModal.style.display = 'flex';
                
                // 生成每个二维码
                let completedCount = 0;
                const totalCount = lines.length;
                
                lines.forEach((line, index) => {
                    const qrItem = document.createElement('div');
                    qrItem.className = 'batch-qr-item';
                    
                    const canvas = document.createElement('canvas');
                    const textDiv = document.createElement('div');
                    textDiv.className = 'batch-qr-text';
                    textDiv.textContent = line.length > 50 ? line.substring(0, 50) + '...' : line;
                    
                    const actionsDiv = document.createElement('div');
                    actionsDiv.className = 'batch-qr-actions';
                    
                    const downloadBtn = document.createElement('button');
                    downloadBtn.innerHTML = '<i class="fas fa-download"></i>';
                    downloadBtn.title = '下载';
                    downloadBtn.addEventListener('click', function() {
                        const link = document.createElement('a');
                        link.download = `qrcode_${index + 1}.png`;
                        link.href = canvas.toDataURL();
                        link.click();
                        showNotification(`二维码 ${index + 1} 已下载！`);
                    });
                    
                    const copyBtn = document.createElement('button');
                    copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
                    copyBtn.title = '复制图片';
                    copyBtn.addEventListener('click', function() {
                        canvas.toBlob(function(blob) {
                            const item = new ClipboardItem({ 'image/png': blob });
                            navigator.clipboard.write([item]).then(function() {
                                showNotification(`二维码 ${index + 1} 图片已复制到剪贴板！`);
                            }).catch(function(error) {
                                showNotification('复制失败，请尝试下载功能', true);
                            });
                        });
                    });
                    
                    actionsDiv.appendChild(downloadBtn);
                    actionsDiv.appendChild(copyBtn);
                    
                    qrItem.appendChild(canvas);
                    qrItem.appendChild(textDiv);
                    qrItem.appendChild(actionsDiv);
                    
                    batchQrGrid.appendChild(qrItem);
                    
                    // 生成二维码
                    QRCode.toCanvas(canvas, line, {
                        width: 200,
                        height: 200,
                        margin: 2,
                        color: {
                            dark: getComputedStyle(document.documentElement).getPropertyValue('--text-color').trim(),
                            light: getComputedStyle(document.documentElement).getPropertyValue('--card-background').trim()
                        }
                    }, function(error) {
                        completedCount++;
                        
                        if (error) {
                            console.error(`生成第 ${index + 1} 个二维码失败:`, error);
                            qrItem.innerHTML = `<div style="color: var(--error-color); padding: 20px;">生成失败</div>`;
                        }
                        
                        // 更新计数
                        batchCountText.textContent = `共生成 ${completedCount} 个二维码`;
                        
                        if (completedCount === totalCount) {
                            showNotification(`批量生成完成！共生成 ${totalCount} 个二维码`);
                        }
                    });
                });
            });
            
            // 关闭批量弹框
            batchModalClose.addEventListener('click', function() {
                batchModal.style.display = 'none';
            });
            
            // 点击弹框背景关闭
            batchModal.addEventListener('click', function(e) {
                if (e.target === batchModal) {
                    batchModal.style.display = 'none';
                }
            });
            
            // 批量下载全部
            batchDownloadAll.addEventListener('click', function() {
                const canvases = batchQrGrid.querySelectorAll('canvas');
                if (canvases.length === 0) {
                    showNotification('没有可下载的二维码！', true);
                    return;
                }
                
                canvases.forEach((canvas, index) => {
                    setTimeout(() => {
                        const link = document.createElement('a');
                        link.download = `qrcode_${index + 1}.png`;
                        link.href = canvas.toDataURL();
                        link.click();
                    }, index * 100); // 延迟下载避免浏览器阻止
                });
                
                showNotification(`开始下载 ${canvases.length} 个二维码文件...`);
            });
            
            // 下载二维码
            downloadBtn.addEventListener('click', function() {
                const link = document.createElement('a');
                link.download = 'qrcode.png';
                link.href = qrCanvas.toDataURL();
                link.click();
                showNotification('二维码已下载！');
            });
            
            // 复制二维码图片
            copyBtn.addEventListener('click', function() {
                qrCanvas.toBlob(function(blob) {
                    const item = new ClipboardItem({ 'image/png': blob });
                    navigator.clipboard.write([item]).then(function() {
                        showNotification('二维码图片已复制到剪贴板！');
                    }).catch(function(error) {
                        showNotification('复制失败，请尝试下载功能', true);
                    });
                });
            });
            
            // 键盘快捷键支持
            qrInput.addEventListener('keydown', function(e) {
                if (e.ctrlKey && e.key === 'Enter') {
                    generateBtn.click();
                }
            });
            
            // 通用复制到剪贴板函数
            function copyToClipboard(text) {
                const textarea = document.createElement('textarea');
                textarea.value = text;
                document.body.appendChild(textarea);
                textarea.select();
                document.execCommand('copy');
                document.body.removeChild(textarea);
            }
            
            // 显示通知
            function showNotification(message, isError = false) {
                notification.textContent = message;
                notification.className = 'notification show';
                if (isError) {
                    notification.classList.add('error');
                }
                
                setTimeout(() => {
                    notification.classList.remove('show');
                    setTimeout(() => {
                        notification.classList.remove('error');
                    }, 300);
                }, 3000);
            }
        });
    </script>
    
    <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?3615c6485313357fe26e486bf42d9ec2";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
    </script>
</body>
</html>